import java.util.*;

class Student implements Comparable<Student>{
    public int age;
    public String name;
    public Student(String name,int age){
        this.name=name;
        this.age=age;
    }
    @Override
    public boolean equals(Object o){
        if(this==o){
            return true;
        }
        if(o==null||getClass()!=o.getClass()){
            return false;
        }
        Student student=(Student) o;
        return age==student.age && Objects.equals(name,student.name);
    }
    @Override
    public int hashCode(){
        return Objects.hash(age,name);
    }
    @Override
    public int compareTo(Student o){
        return this.age-o.age;//小根堆
        //return o.age-this.age;//大根堆
    }
}

class NameComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1,Student o2){
        return o1.name.compareTo(o2.name);
    }
}

class AgeComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1,Student o2){
        return o2.age-o1.age;
    }
}

class Icmp implements Comparator<Integer>{
    @Override
    public int compare(Integer o1,Integer o2){
        return o2.compareTo(o1);
    }
}

public class test_1_10_1 {
    public static void main(String[] args) {
        TestHeap testHeap=new TestHeap();
        int[] arr={27,15,19,18,28,34,65,49,25,37};
        testHeap.initElem(arr);
        testHeap.createHeap();
        System.out.println(testHeap.peek());
        testHeap.pop();
        System.out.println(testHeap.peek());
        testHeap.push(50);
        System.out.println(testHeap.peek());
    }

//    public static void main(String[] args) {
//        List<Integer> list=new ArrayList<>();
//        //小根堆
//        Queue<Integer> priorityQueue1=new PriorityQueue<>(list);
//        priorityQueue1.offer(10);
//        priorityQueue1.offer(2);
//        System.out.println(priorityQueue1.poll());
//        System.out.println(priorityQueue1.peek());
//
//        Queue<Student> priorityQueue2=new PriorityQueue<>();
//        priorityQueue2.offer(new Student("zhangsan",10));
//        priorityQueue2.offer(new Student("lisi",20));
////        priorityQueue2.offer(null);   //error
//
//    }

//    public static void main(String[] args) {
//        int[] array={1,21,5,12,6,3,2,77};
//        int[] ret=maxK(array,3);
//        System.out.println(Arrays.toString(ret));
//    }
//    public static int[] maxK(int[] arr,int k){
//        int[] ret=new int[k];
//        if(arr==null||k==0){
//            return ret;
//        }
//        Queue<Integer> minHeap=new PriorityQueue<>(k);
//        //遍历数组的前k个，放到堆中
//        for (int i = 0; i < k; i++) {
//            minHeap.offer(arr[i]);
//        }
//        //遍历剩下的k-1个，每次和堆顶元素比较
//        //堆顶元素小时，就出堆
//        for (int i = k; i < arr.length; i++) {
//            int val=minHeap.peek();
//            if(val<arr[i]){
//                minHeap.poll();
//                minHeap.offer(arr[i]);
//            }
//        }
//        for (int i = 0; i < k; i++) {
//            ret[i]=minHeap.poll();
//        }
//        return ret;
//    }

//    public int[] smallestK(int[] arr,int k){
//        int[] ret=new int[k];
//        if(arr==null||k==0){
//            return ret;
//        }
//        Queue<Integer> minHeap=new PriorityQueue<>(arr.length);
//        for (int x:arr) {
//            minHeap.offer(x);
//        }
//        for (int i = 0; i < k; i++) {
//            ret[i]=minHeap.poll();
//        }
//        return ret;
//    }
//    public static void main(String[] args) {
//        Student student1=new Student("zhangsan",10);
//        Student student2=new Student("lisi",20);
//
//        System.out.println(student1==student2);
//        System.out.println(student1.equals(student2));
//        System.out.println(student1.compareTo(student2));
//
//        NameComparator nameComparator=new NameComparator();
//        int ret=nameComparator.compare(student1,student2);
//        System.out.println(ret);
//
//        AgeComparator ageComparator=new AgeComparator();
//        int ret2=ageComparator.compare(student1,student2);
//        System.out.println(ret2);
//
//    }

//    public static void main(String[] args){
//        AgeComparator ageComparator=new AgeComparator();
//        Queue<Student> priorityQueue=new PriorityQueue<>(ageComparator);
//        priorityQueue.offer(new Student("zhangsan",20));
//        priorityQueue.offer(new Student("lisi",30));
//
//        Queue<Integer> priorityQueue1=new PriorityQueue<>((o1,o2)->{return o2.compareTo(o1);});
//        priorityQueue1.offer(1);
//        priorityQueue1.offer(2);
//    }


}









